package cn.wolfcode.domain;

import cn.hutool.core.date.BetweenFormater;
import cn.hutool.core.date.DateUtil;
import cn.wolfcode.enums.NoticeLevelEnum;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Notice {
    /** 主键*/
    private Long id;

    /** 公告标题*/
    private String title;

    /** 创建人*/
    private Employee creat;

    /** 创建时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date creatTime;

    /** 公告级别*/
    private Integer level;

    /** 是否已读*/
    private Boolean readStatus;

    /** 发布状态*/
    private Boolean issueStatus;

    /**公告内容*/
    private String context;

    /**后台登陆的用户*/
    private Employee user;

    public String getLevelName(){
        return NoticeLevelEnum.findName(level);
    }
    public String toJson(){
        Map map = new HashMap();
        map.put("id",id);
        map.put("title",title);
        map.put("context",context);
        map.put("level",level);
        return JSON.toJSONString(map);
    }


    public String getMisTime(){
        if(creatTime!=null){
            return DateUtil.formatBetween(new Date(),creatTime, BetweenFormater.Level.MINUTE);
        }
        return null;
    }
}